import {SysNewsData, SysNewsAdd} from "@/pages/news/type";
import {ReactNode} from "react";
import {UseFetchDataAction} from "@ant-design/pro-table/es/typing";
import {Button, DatePicker, DatePickerProps, Select, SelectProps, Space} from "antd";
import {ProColumns} from "@ant-design/pro-table";
import {OptionActions} from "@/type/type";
import AddSysNews from "@/pages/news/list/components/AddSysNews";
import AuthWrapper from "@/components/AuthWrapper";
import DebounceSelect from "@/components/CProForm/components/DebounceSelect";
import {RangePickerProps} from "antd/es/date-picker/generatePicker";

// @ts-ignore
const columns: ProColumns<SysNewsData> = (optionAction: OptionActions<SysNewsAdd, SysNewsData>, newsCategoryList: SelectProps["options"],
                                          newsTagList: SelectProps["options"], setCreateTime: any) => {
  return [
    {
      dataIndex: "index",
      valueType: "index",
    },
    {
      title: "标题",
      dataIndex: "title",
      align: 'center',
    },
    {
      title: "分类",
      dataIndex: "categoryName",
      align: 'center',
      hideInSearch: true,
      renderFormItem: () => {
        return (
          <Select options={newsCategoryList}
          ></Select>
        )
      },
    },
    {
      title: "分类",
      dataIndex: "categoryId",
      align: 'center',
      hideInTable:true,
      renderFormItem: () => {
        return (
          <Select options={newsCategoryList}
          ></Select>
        )
      },
    },
    {
      title: "标签",
      dataIndex: "tagName",
      align: 'center',
      hideInSearch: true,
      renderFormItem: () => {
        return (
          <Select options={newsTagList}
          ></Select>
        )
      },
    },
    {
      title: "标签",
      dataIndex: "tagId",
      align: 'center',
      hideInTable:true,
      renderFormItem: () => {
        return (
          <Select options={newsTagList}
          ></Select>
        )
      },
    },
    {
      title: "内容",
      dataIndex: "content",
      align: 'center',
    },
    {
      title: "图片",
      dataIndex: "picUrl",
      align: 'center',
    },
    {
      title: "状态",
      dataIndex: "status",
      align: 'center',

    },
    {
      title: "创建时间",
      dataIndex: "createTime",
      align: 'center',
      renderFormItem: ()=>{
        const { RangePicker } = DatePicker;
        const onOk = (value: DatePickerProps['value'] | RangePickerProps['value']) => {
          console.log('onOk: ', value);
        };
        return (
          <RangePicker
            showTime={{ format: 'HH:mm:ss' }}
            format="YYYY-MM-DD HH:mm:ss"
            onChange={(value, dateString) => {
              console.log('Selected Time: ', value);
              console.log('Formatted Selected Time: ', dateString);
              setCreateTime(dateString)
            }}
            onOk={onOk}
          />
        )
      }
    },

    {
      title: "操作",
      valueType: 'option',
      align: "center",
      key: "option",
      width: "200px",
      render: (text: ReactNode, record: SysNewsData, index: number, action: UseFetchDataAction<SysNewsData>) => {
        return (
          <Space>
               <AddSysNews initialValues={record} newsCategoryList={newsCategoryList} newsTagList={newsTagList}
                                                    {...optionAction.editModal(record, true)}/>
             <Button type="link"  danger onClick={() =>
                optionAction.remove([record.id])}>删除</Button>
          </Space>
        )
      }
    }
  ]


}


export default columns;
